package com.duanjw.springboot.shardingsphere.config;

import static com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS;

import org.springframework.context.annotation.Configuration;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * 自定义jackson配置
 * @author duanjw
 */
@Configuration
public class JacksonConfig extends ObjectMapper {
    public JacksonConfig() {
        // 返回为 null 的值去除
        this.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        // 反序列化时，忽略未知属性
        this.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        // 返回的时间不是时间戳
        this.disable(WRITE_DATES_AS_TIMESTAMPS);
        //解决延迟加载的对象
        //this.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS,false);

    }
}
